% EPC flow charts
% Author: Fabian Schuh
\documentclass{paper}

\usepackage[utf8]{inputenc}
\usepackage[english, russian]{babel}


\usepackage{pgf}
\usepackage{tikz}
%%%<
\usepackage{verbatim}
\usepackage[active,tightpage]{preview}
\PreviewEnvironment{tikzpicture}
\setlength\PreviewBorder{5pt}%
%%%>

\usepackage[utf8]{inputenc}
\usetikzlibrary{arrows,automata}
\usetikzlibrary{positioning}


\tikzset{
    state/.style={
           rectangle,
           minimum size=0.8cm,
           fill=blue!10, 
           draw=black, 
           inner sep=4pt,
           text centered,
           font=\fontsize{12}{12}\selectfont
           },	
    box/.style={
           rectangle,
           minimum size=0.7cm,          
           draw=black, 
           inner sep=4pt,
           text centered,
           },	
     pil/.style={
           >=latex',
           very thick,
           draw=black, 
           shorten <=1pt,
           shorten >=1pt}
}

\begin{document}

\begin{tikzpicture}

\newcommand{\boxesLineV}[3] {
    \begin{scope}[shift={#1}]
        \foreach \x in {1,...,#2} {
          \node[state] at (0, \x * 0.8 cm) {#3.\x};
        }
    \end{scope}
}

\newcommand{\boxesLineH}[3] {
    \begin{scope}[shift={#1}]
        \foreach \x in {1,...,#2} {
          \node[state] at (\x * 0.8 cm, 0) {#3.\x};
        }
    \end{scope}
}

\path[->, pil] (2, 2 + 0.4) -- (-4 + 0.8, 1.4);

\path[->, pil] (3, 2 + 0.4) -- (-4 + 4 * 0.8, 1.4);

\path[->, pil] (4, 2 + 0.4) -- (-4 + 8 * 0.8, 1.4);

\path[->, pil] (5, 2 + 0.4) -- (-4 + 10 * 0.8, 1.4);

\path[->, pil] (6, 2 + 0.4) -- (-4 + 15 * 0.8, 1.4);

\path[->, pil] (7, 2 + 0.4) -- (-4 + 18 * 0.8, 1.4);

\boxesLineV{(2, 4.5)}{3}{1} 
\boxesLineV{(3, 4.5)}{4}{2} 
\boxesLineV{(4, 4.5)}{2}{3} 
\boxesLineV{(5, 4.5)}{5}{4} 
\boxesLineV{(6, 4.5)}{3}{5} 
\boxesLineV{(7, 4.5)}{4}{6} 

\node at (0.4, 4.2){\Large размер:};
\node at (-0.9, 3) {\Large префиксная сумма:};

\node[box] at (2, 4.2) {3};
\node[box] at (3, 4.2) {4};
\node[box] at (4, 4.2) {2};
\node[box] at (5, 4.2) {5};
\node[box] at (6, 4.2) {3};
\node[box] at (7, 4.2) {4};

\node[box] at (2, 3) {0};
\node[box] at (3, 3) {3};
\node[box] at (4, 3) {7};
\node[box] at (5, 3) {9};
\node[box] at (6, 3) {13};
\node[box] at (7, 3) {16};


\boxesLineH{(-4, 0.9)}{3}{1} (a1)
\boxesLineH{(-4 + 3 * 0.8, 0.9)}{4}{2}
\boxesLineH{(-4 + 7 * 0.8, 0.9)}{2}{3}
\boxesLineH{(-4 + 9 * 0.8, 0.9)}{5}{4}
\boxesLineH{(-4 + 14 * 0.8, 0.9)}{3}{5}
\boxesLineH{(-4 + 17 * 0.8, 0.9)}{4}{6}


\end{tikzpicture}

\end{document}
